.com
Hosted by:
Unit testing expertise at your fingertips!
Home | Discuss | Lists

Database as SUT API?

A common technique for setting up test fixtures is Back Door Setup (see Back Door Manipulation on page X) and for verifying test outcomes, Back Door Verification (see Back Door Manipulation). But when is a test that is interacting directly with the database behind a system under test (SUT) not considered to be going through the "back door"?

On a recent project, some friends were struggling with this very question although at first, they didn't realize it. One of their analysts who was also a power user seemed overly focused on the database schema. At first, they put this down to a Powerbuilder background and tried to break him of the habit. That didn't work. The analyst just dug in his heels. They tried explaining that on agile projects it was important not to try to define the whole data schema at the beginning of the project and that this required them to evolve the schema as the requirements were implemented.

Of course, the analyst complained every time they modified the database schema as it broke all his queries. As the project unfolded, they slowly started to understand that the analyst really did need a stable database against which to run queries. It was his way to get at the data generated by the system.

Once they understood this, they were able to treat this query schema as a formal interface provided by the system. Customer tests were written against this interface and developers had to ensure that those tests still passed whenever they changed the database. To minimize the impact of database refactorings, they defined a set of query views that implemented this interface. This allowed them to refactor the database as needed.

When might you find yourself in this situation? Any time your customer uses reporting tools (such as Crystal Reports) against your database, there is an argument to be made as to whether part of the requirements is a stable reporting interface. Similarly, if the customer uses scripts (such as DTS or SQL) to load data into the database, the argument can be made that there is a requirement for a stable data loading interface.



Page generated at Wed Feb 09 16:39:03 +1100 2011

Copyright © 2003-2008 Gerard Meszaros all rights reserved

All Categories
Introductory Narratives
Web Site Instructions
Code Refactorings
Database Patterns
DfT Patterns
External Patterns
Fixture Setup Patterns
Fixture Teardown Patterns
Front Matter
Glossary
Misc
References
Result Verification Patterns
Sidebars
Terminology
Test Double Patterns
Test Organization
Test Refactorings
Test Smells
Test Strategy
Tools
Value Patterns
XUnit Basics
xUnit Members
All "Sidebars"
Ariane
Class - Instance Duality
Database as SUT API?
Faster Tests Without Shared Fixtures
Testing Stored Procs with JUnit
There's Always an Exception
Transaction Rollback Pain
Unit Test Rulz
Using Delta Assertions to Detect Data Leakage
What's in a (Pattern) Name?
Why Do We Need 100 Customers?